<template>
    <div class="addPermissionList">
        <el-dialog
            center
            :before-close="handClose"
            width="30%"
            title="新增权限"
            :visible.sync="off"
            append-to-body>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" size="mini" class="demo-ruleForm">
                <el-form-item label="权限名" prop="permissionName">
                    <el-input v-model.trim="ruleForm.permissionName"></el-input>
                </el-form-item>
                <el-form-item label="权限地址" prop="url">
                    <el-input v-model.trim="ruleForm.url"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="create">立即创建</el-button>
            </div>
        </el-dialog>
    </div>
   
</template>

<script>
    import { addPerssion } from "@/api/jurisdiction.js"
    export default {
        name: "add",
        props: {
            off: {
                type: Boolean
            }
        },
        data(){
            return {
                rules: {
                     permissionName: [
                        {
                            required: true,
                            message: "权限名称不能为空",
                            trigger: "blur"
                        }
                    ],
                    url: [
                        {
                            required: true,
                            message: "地址不能为空",
                            trigger: "blur"
                        }
                    ]
                },
                ruleForm: {
                    permissionName: "",
                    url:""
                }
            }
        },
        methods: {
            handClose(){
                this.$emit("update:off", false);
            },
            create(){
                this.$refs.ruleForm.validate((valid) => {
                    if(!valid){
                        return;
                    }else{
                        // var obj = {
                        //     permissionName: this.ruleForm.permissionName,
                        //     url: this.ruleForm.url
                        // }
                        addPerssion({
                            permissionName: this.ruleForm.permissionName,
                            url: this.ruleForm.url
                        }).then(
                            res => {
                                console.log("res新增权限", res);
                                this.$message({
                                    type: "success",
                                    message: "新增权限成功"
                                });
                                this.$emit("update:off", false);
                                this.$parent.getList();
                                this.ruleForm.resetFields();
                            },
                            err => {}
                        );
                    }
                });
            }
        }
    }
</script>

<style scoped lang="less">

</style>